name: Deploy site

on:
  push:
    branches: [ master ]

jobs:
  doc-deploy:
    runs-on: ubuntu-22.04

    steps:
      - uses: actions/checkout@v3
        with:
          persist-credentials: false

      - name: Set up Python 3.x
        uses: actions/setup-python@v4
        with:
          # Semantic version range syntax or exact version of a Python version
          python-version: '3.11.0'

      # You can test your matrix by printing the current Python version
      - name: Display Python version
        run: python -c "import sys; print(sys.version)"

      - name: Cache pip
        uses: actions/cache@v3
        with:
          # This path is specific to Ubuntu
          path: ~/.cache/pip
          # Look to see if there is a cache hit for the corresponding requirements file
          key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-
            ${{ runner.os }}-

      - name: Install dependencies
        run: pip install -r requirements.txt

      - name: Run Mkdocs
        # Build the site using mkdocs
        run: mkdocs build --verbose --clean --strict

      - name: Post-Mkdocs touch/copy files
        # miscellaneous files needed for GitHub etc
        run: |
          touch site/.nojekyll
          cp CNAME site/CNAME

      - name: Deploy 🚀
        uses: JamesIves/github-pages-deploy-action@v4.4.1
        with:
          branch: gh-pages # The branch the action should deploy to.
          folder: site # The folder the action should deploy.
          clean: true # Automatically remove deleted files from the deploy branch
